﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate;
using FluentNHibernate.Mapping;
using Spaanjaars.ContactManager.Model;

namespace Spaanjaars.ContactManager.Repository.NH.MappingFiles
{
    public class ContactPersonMap : ClassMap<ContactPerson>
    {        
        public ContactPersonMap()
        {         
            Table("ContactPeople");
            Not.LazyLoad();
            Id(cp => cp.Id);
            Map(cp => cp.DateOfBirth);
            Component(cp => cp.Name, name =>
                                         {
                                             name.Map(n => n.FirstName);
                                             name.Map(n => n.MiddleName);
                                             name.Map(n => n.LastName);
                                         });

            HasMany<ContactPersonAddress>(Reveal.Property<ContactPerson>("Addresses"))
                .KeyColumn("Id");
        }
    }
}
